import uuid
from django.db import models
from django.contrib.auth import get_user_model

User = get_user_model()

class ChatMessage(models.Model):
    message_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='chat_messages')
    role = models.CharField(max_length=20)  # 'user' or 'assistant'
    content = models.TextField()
    timestamp = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-timestamp']

class Reference(models.Model):
    message = models.ForeignKey(ChatMessage, on_delete=models.CASCADE, related_name='references')
    title = models.CharField(max_length=200)
    content = models.TextField()
    source = models.CharField(max_length=100)

    class Meta:
        ordering = ['id'] 